package com.eightbears.beboy.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.cache.DistrictCache;
import com.eightbears.beboy.base.cache.MyAddressCache;
import com.eightbears.beboy.entity.ShoppingAddressEntity;
import com.eightbears.greendao.District;
import com.eightbears.greendao.MyAddress;

public class ShoppingAddressAdapter extends BaseQuickAdapter<ShoppingAddressEntity.ShoppingAddress, BaseViewHolder> {

    public ShoppingAddressAdapter() {
        super(R.layout.item_shopping_address, null);

    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ShoppingAddressEntity.ShoppingAddress item) {
        District province = DistrictCache.getInstance(mContext).getCacheById(item.getProvince_id());
        District city = DistrictCache.getInstance(mContext).getCacheById(item.getCity_id());
        District district = DistrictCache.getInstance(mContext).getCacheById(item.getDistrict_id());
        MyAddress myAddress = MyAddressCache.getInstance(mContext).getData();
        String proviceName = province.getName();
        String cityName = city.getName();
        if (proviceName.equals(cityName)) {
            cityName = "";
        }

        baseViewHolder.setText(R.id.tv_getadress_name, item.getName())
                .addOnClickListener(R.id.tv_getaddress_bianji)
                .addOnClickListener(R.id.tv_getaddress_detele)
                .addOnClickListener(R.id.ll_moren);
        baseViewHolder.setText(R.id.tv_getadress_number, item.getMobile());
        String address = proviceName + cityName + district.getName() + item.getAddress();
        baseViewHolder.setText(R.id.tv_getadress_address, address);

        ImageView radioSel = baseViewHolder.getView(R.id.rb_moren);
        radioSel.setImageResource(R.mipmap.icon_radio);

        if(myAddress != null && item.getId().equals(myAddress.getMyAddressId())) {
            radioSel.setImageResource(R.mipmap.icon_radio_sel);
        }

    }

}

